using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class ItemTypeMap : EntityTypeConfiguration<ItemType>
    {
        public ItemTypeMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.NAME)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.REVACCT)
                .HasMaxLength(40);

            this.Property(t => t.INVACCT)
                .HasMaxLength(40);

            this.Property(t => t.COSACCT)
                .HasMaxLength(40);

            this.Property(t => t.PRMCHGACCT)
                .HasMaxLength(40);

            this.Property(t => t.CODE)
                .HasMaxLength(15);

            this.Property(t => t.CUSTOM1)
                .HasMaxLength(30);

            this.Property(t => t.CUSTOM2)
                .HasMaxLength(30);

            this.Property(t => t.CUSTOM3)
                .HasMaxLength(30);

            this.Property(t => t.CUSTOM4)
                .HasMaxLength(30);

            this.Property(t => t.CUSTOM5)
                .HasMaxLength(30);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            this.Property(t => t.GuarDiscAcct)
                .HasMaxLength(40);

            this.Property(t => t.CodeName)
                .HasMaxLength(50);

            this.Property(t => t.itp_InvAcctWithVAT)
                .HasMaxLength(40);

            this.Property(t => t.IT_TP_Order)
                .HasMaxLength(2);

            // Table & Column Mappings
            this.ToTable("ItemType");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.NAME).HasColumnName("NAME");
            this.Property(t => t.BILLORDER).HasColumnName("BILLORDER");
            this.Property(t => t.CRITERIA).HasColumnName("CRITERIA");
            this.Property(t => t.INVENTORY).HasColumnName("INVENTORY");
            this.Property(t => t.REVACCT).HasColumnName("REVACCT");
            this.Property(t => t.INVACCT).HasColumnName("INVACCT");
            this.Property(t => t.COSACCT).HasColumnName("COSACCT");
            this.Property(t => t.PRMCHGACCT).HasColumnName("PRMCHGACCT");
            this.Property(t => t.PROTECTED).HasColumnName("PROTECTED");
            this.Property(t => t.CODE).HasColumnName("CODE");
            this.Property(t => t.TYPEORD).HasColumnName("TYPEORD");
            this.Property(t => t.SHOWTYPE).HasColumnName("SHOWTYPE");
            this.Property(t => t.CUSTOM1).HasColumnName("CUSTOM1");
            this.Property(t => t.CUSTOM2).HasColumnName("CUSTOM2");
            this.Property(t => t.CUSTOM3).HasColumnName("CUSTOM3");
            this.Property(t => t.CUSTOM4).HasColumnName("CUSTOM4");
            this.Property(t => t.CUSTOM5).HasColumnName("CUSTOM5");
            this.Property(t => t.IBUY).HasColumnName("IBUY");
            this.Property(t => t.ISELL).HasColumnName("ISELL");
            this.Property(t => t.LABTEST).HasColumnName("LABTEST");
            this.Property(t => t.RADIOLOGY).HasColumnName("RADIOLOGY");
            this.Property(t => t.REQ_TYPE).HasColumnName("REQ_TYPE");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");
            this.Property(t => t.EXPIRYDATEENABLED).HasColumnName("EXPIRYDATEENABLED");
            this.Property(t => t.VAT).HasColumnName("VAT");
            this.Property(t => t.LEFTTRAILINGZEROSENABLED).HasColumnName("LEFTTRAILINGZEROSENABLED");
            this.Property(t => t.ChkConsultant).HasColumnName("ChkConsultant");
            this.Property(t => t.DENTAL).HasColumnName("DENTAL");
            this.Property(t => t.Pharmacy).HasColumnName("Pharmacy");
            this.Property(t => t.cstctrid).HasColumnName("cstctrid");
            this.Property(t => t.Fixedasset).HasColumnName("Fixedasset");
            this.Property(t => t.GuarDiscAcct).HasColumnName("GuarDiscAcct");
            this.Property(t => t.frs).HasColumnName("frs");
            this.Property(t => t.Chartable).HasColumnName("Chartable");
            this.Property(t => t.CodeName).HasColumnName("CodeName");
            this.Property(t => t.OrderType).HasColumnName("OrderType");
            this.Property(t => t.itp_InvAcctWithVAT).HasColumnName("itp_InvAcctWithVAT");
            this.Property(t => t.IT_TP_Order).HasColumnName("IT_TP_Order");

            // Relationships
            this.HasOptional(t => t.Acct)
                .WithMany(t => t.ItemTypes)
                .HasForeignKey(d => d.COSACCT);
            this.HasOptional(t => t.Acct1)
                .WithMany(t => t.ItemTypes1)
                .HasForeignKey(d => d.INVACCT);
            this.HasOptional(t => t.Acct2)
                .WithMany(t => t.ItemTypes2)
                .HasForeignKey(d => d.PRMCHGACCT);
            this.HasOptional(t => t.Acct3)
                .WithMany(t => t.ItemTypes3)
                .HasForeignKey(d => d.REVACCT);
            this.HasOptional(t => t.itemcrit)
                .WithMany(t => t.ItemTypes)
                .HasForeignKey(d => d.CRITERIA);

        }
    }
}
